package com.micro.service.common.base;



import com.micro.service.common.enums.AuthorizationServerEnum;
import com.micro.service.common.enums.SysErrorEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lvxiucai
 * @description
 * @date 2019/7/11
 */
public class ResultBase extends HashMap<String,Object> {

    public ResultBase(AuthorizationServerEnum eEnum){
        super();
        put("code",eEnum.getCode());
        put("msg",eEnum.getMessage());
    }

    public ResultBase(String code, String msg){
        super();
        put("code",SysErrorEnum.SYS_SUCCESS.getCode());
        put("msg",SysErrorEnum.SYS_SUCCESS.getMsg());
    }

    public ResultBase(int code, String msg){
        super();
        put("code",SysErrorEnum.SYS_SUCCESS.getCode());
        put("msg",SysErrorEnum.SYS_SUCCESS.getMsg());
    }


    public ResultBase() {
        put("code",SysErrorEnum.SYS_SUCCESS.getCode());
        put("msg",SysErrorEnum.SYS_SUCCESS.getMsg());
    }

    public static ResultBase error(){
        return error(Integer.parseInt(SysErrorEnum.SYS_ERROR.getCode()),SysErrorEnum.SYS_ERROR.getMsg());
    }

    public static ResultBase error(String msg){
        return error(Integer.parseInt(SysErrorEnum.SYS_ERROR.getCode()),msg);
    }

    public static ResultBase error(int code,String msg){
        ResultBase ResultBase = new ResultBase();
        ResultBase.put("code",code);
        ResultBase.put("msg",msg);
        return ResultBase;
    }

    public static ResultBase OK(){
        return new ResultBase();
    }

    public static ResultBase OK(Map<String,Object> map){
        ResultBase ResultBase = new ResultBase();
        ResultBase.putAll(map);
        return ResultBase;
    }

    public static ResultBase OK(String msg){
        ResultBase ResultBase = new ResultBase();
        ResultBase.put("code", SysErrorEnum.SYS_SUCCESS.getCode());
        ResultBase.put("msg",msg);
        return ResultBase;
    }

    @Override
    public ResultBase put(String key,Object value){
        super.put(key,value);
        return this;
    }
    
}
